<template>
  <div class="login_wrap">
       <div class="login_box">
           <div class="login_box_header">
             登陆页面
           </div>
           <ul class="login_wrap_input">
             <li>
               <input type="text" class="input_username" placeholder="账号" ref="input_1">
             </li>
             <li>
               <input type="password" class="input_pwd" placeholder="密码" ref="input_2">
             </li>
           </ul>
          <div class="certain_btn" @click="login">
               登录
          </div>
       </div>
    <transition name="fade">
      <Loading v-if="Load"></Loading>
    </transition>
  </div>
</template>
<script>
  import {mapState, mapMutations,mapActions,mapGetters} from 'vuex'
  import store from '../vuex/store_index';
  import axios from  "axios"
  import Loading from "./Loading.vue"
  export default {
    name: 'bottom_btn',
    data () {
      return {
        object: this.$store.getters.Get_Bot_C_obj,
        sign_c: true,
        Load: false
      }
    },
    computed: mapState([
//      'Loading'
    ]),
    components: {
      Loading
    },
    methods: {
      ...mapMutations([
          "Change_loading_show"
      ]),
      ...mapActions([
           "Loading_show",
           "thom_redirect",
           "get_user_info"
      ]),
      ...mapGetters([
        ""
      ]),
      mounted(){
      },
      created(){
//          alert(this.Load)
      },
      login(){
        this.Load = !this.Load;
        let params = new URLSearchParams();
        params.append('username', this.$refs.input_1.value);
        params.append('password', this.$refs.input_2.value);
        axios.post('/easy_stock/background/login', params)
        .then((res)=> {
            if(res.data.code == 0){
              axios.get('/easy_stock/background/user_info/get')
                .then((res)=>{
                  if(res.data.code == 0){
                    setTimeout(()=> {
                      this.Load = !this.Load;
                      sessionStorage.setItem("user_login",true);
//                    this.$store.comment("Loading_show")
                      this.$store.commit("get_user_info",res);
                      this.$store.dispatch("thom_redirect",{name:"/index/in",router:this.$router});
                    },400)
                  }else{
                    this.Load = !this.Load;
                     alert("登陆失败")
                  }

                }).
                catch((res)=>{
                   setTimeout( ()=> {
                     this.Load = !this.Load;
//                     alert("网络出错")
//                     this.$store.comment("get_user_info",res)
                   },400)
                })
//          this.$store.dispatch("thom_redirect",{name:"/index",router:this.$router})
            }else{
              this.Load = !this.Load;
            }
        });
      }
    }
  }
</script>
<style scoped>

  /*certain btn e*/
</style>
